{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "\n",
    "# 1> 数据划分 取20%做测试样本，剩下做训练样本\n",
    "\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "\n",
    "dt = pd.read_excel('model.xls')\n",
    "simpler = np.random.permutation(len(dt))\n",
    "dt = dt.take(simpler) #导入随机函数shuffle，用来打乱数据 注意：不能用shuffle\n",
    "dt = dt.as_matrix() #将表格转成矩阵格式\n",
    "\n",
    "\n",
    "p=0.8 #设置训练集的比例\n",
    "train = dt[:int(len(dt)*p), :] #前80%为训练集\n",
    "test = dt[int(len(dt)*p):, :] #后20%为测试集\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using Theano backend.\n",
      "D:\\Anaconda2\\lib\\site-packages\\ipykernel_launcher.py:8: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(units=10, input_dim=3)`\n",
      "  \n",
      "D:\\Anaconda2\\lib\\site-packages\\ipykernel_launcher.py:10: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(units=1, input_dim=10)`\n",
      "  # Remove the CWD from sys.path while we load stuff.\n",
      "D:\\Anaconda2\\lib\\site-packages\\keras\\models.py:844: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.\n",
      "  warnings.warn('The `nb_epoch` argument in `fit` '\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/1000\n",
      "232/232 [==============================] - 0s - loss: 0.9159     \n",
      "Epoch 2/1000\n",
      "232/232 [==============================] - 0s - loss: 0.5644     \n",
      "Epoch 3/1000\n",
      "232/232 [==============================] - 0s - loss: 0.5062     \n",
      "Epoch 4/1000\n",
      "232/232 [==============================] - 0s - loss: 0.4587     \n",
      "Epoch 5/1000\n",
      "232/232 [==============================] - 0s - loss: 0.4193     \n",
      "Epoch 6/1000\n",
      "232/232 [==============================] - 0s - loss: 0.3929     \n",
      "Epoch 7/1000\n",
      "232/232 [==============================] - 0s - loss: 0.3677     \n",
      "Epoch 8/1000\n",
      "232/232 [==============================] - 0s - loss: 0.3476     \n",
      "Epoch 9/1000\n",
      "232/232 [==============================] - 0s - loss: 0.3238     \n",
      "Epoch 10/1000\n",
      "232/232 [==============================] - 0s - loss: 0.3054     \n",
      "Epoch 11/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2945     \n",
      "Epoch 12/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2829     \n",
      "Epoch 13/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2736     \n",
      "Epoch 14/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2624     \n",
      "Epoch 15/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2535     \n",
      "Epoch 16/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2478     \n",
      "Epoch 17/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2400     \n",
      "Epoch 18/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2357     \n",
      "Epoch 19/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2283     \n",
      "Epoch 20/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2255     \n",
      "Epoch 21/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2196     \n",
      "Epoch 22/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2161     \n",
      "Epoch 23/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2127     \n",
      "Epoch 24/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2093     \n",
      "Epoch 25/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2035     \n",
      "Epoch 26/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2002     \n",
      "Epoch 27/1000\n",
      "232/232 [==============================] - 0s - loss: 0.2026     \n",
      "Epoch 28/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1990     \n",
      "Epoch 29/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1931     \n",
      "Epoch 30/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1952     \n",
      "Epoch 31/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1906     \n",
      "Epoch 32/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1923     \n",
      "Epoch 33/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1866     \n",
      "Epoch 34/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1887     \n",
      "Epoch 35/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1865     \n",
      "Epoch 36/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1815     \n",
      "Epoch 37/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1808     \n",
      "Epoch 38/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1801     \n",
      "Epoch 39/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1787     \n",
      "Epoch 40/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1794     \n",
      "Epoch 41/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1793     \n",
      "Epoch 42/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1751     \n",
      "Epoch 43/1000\n",
      "232/232 [==============================] - ETA: 0s - loss: 0.179 - 0s - loss: 0.1760     \n",
      "Epoch 44/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1728     \n",
      "Epoch 45/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1701     \n",
      "Epoch 46/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1725     \n",
      "Epoch 47/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1717     \n",
      "Epoch 48/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1711     \n",
      "Epoch 49/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1702     \n",
      "Epoch 50/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1712     \n",
      "Epoch 51/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1684     \n",
      "Epoch 52/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1696     \n",
      "Epoch 53/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1679     \n",
      "Epoch 54/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1670     \n",
      "Epoch 55/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1685     \n",
      "Epoch 56/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1678     \n",
      "Epoch 57/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1652     \n",
      "Epoch 58/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1650      \n",
      "Epoch 59/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1675     \n",
      "Epoch 60/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1586     \n",
      "Epoch 61/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1617     \n",
      "Epoch 62/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1646     \n",
      "Epoch 63/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1642     \n",
      "Epoch 64/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1630     \n",
      "Epoch 65/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1606     \n",
      "Epoch 66/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1642     \n",
      "Epoch 67/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1618     \n",
      "Epoch 68/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1619     \n",
      "Epoch 69/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1604     \n",
      "Epoch 70/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1607     \n",
      "Epoch 71/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1614     \n",
      "Epoch 72/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1620     \n",
      "Epoch 73/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1622     \n",
      "Epoch 74/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1603     \n",
      "Epoch 75/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1599     \n",
      "Epoch 76/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1598     \n",
      "Epoch 77/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1569     \n",
      "Epoch 78/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1577     \n",
      "Epoch 79/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1583     \n",
      "Epoch 80/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1586     \n",
      "Epoch 81/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1580     \n",
      "Epoch 82/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1568     \n",
      "Epoch 83/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1536     \n",
      "Epoch 84/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1576     \n",
      "Epoch 85/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1549     \n",
      "Epoch 86/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1571      \n",
      "Epoch 87/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1580     \n",
      "Epoch 88/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1541     \n",
      "Epoch 89/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1564     \n",
      "Epoch 90/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1557     \n",
      "Epoch 91/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1569     \n",
      "Epoch 92/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1564     \n",
      "Epoch 93/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1549     \n",
      "Epoch 94/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1555      \n",
      "Epoch 95/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1557     \n",
      "Epoch 96/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1540     \n",
      "Epoch 97/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1544     \n",
      "Epoch 98/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1537     \n",
      "Epoch 99/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1551     \n",
      "Epoch 100/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1522      \n",
      "Epoch 101/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1540      \n",
      "Epoch 102/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1545     \n",
      "Epoch 103/1000\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "232/232 [==============================] - 0s - loss: 0.1540      \n",
      "Epoch 104/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1537     \n",
      "Epoch 105/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1559     \n",
      "Epoch 106/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1513     \n",
      "Epoch 107/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1523     \n",
      "Epoch 108/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1532     \n",
      "Epoch 109/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1548     \n",
      "Epoch 110/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1524     \n",
      "Epoch 111/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1538     \n",
      "Epoch 112/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1525       \n",
      "Epoch 113/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1509     \n",
      "Epoch 114/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1524       \n",
      "Epoch 115/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1523      \n",
      "Epoch 116/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1533     \n",
      "Epoch 117/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1534      \n",
      "Epoch 118/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1503       \n",
      "Epoch 119/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1514     \n",
      "Epoch 120/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1490      \n",
      "Epoch 121/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1520     \n",
      "Epoch 122/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1519     \n",
      "Epoch 123/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1518      \n",
      "Epoch 124/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1521     \n",
      "Epoch 125/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1531     \n",
      "Epoch 126/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1505     \n",
      "Epoch 127/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1541      \n",
      "Epoch 128/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1501     \n",
      "Epoch 129/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1501     \n",
      "Epoch 130/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1537     \n",
      "Epoch 131/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1485     \n",
      "Epoch 132/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1522     \n",
      "Epoch 133/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1515     \n",
      "Epoch 134/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1501     \n",
      "Epoch 135/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1508     \n",
      "Epoch 136/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1513      \n",
      "Epoch 137/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1489      \n",
      "Epoch 138/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1491     \n",
      "Epoch 139/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1485     \n",
      "Epoch 140/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1469     \n",
      "Epoch 141/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1522     \n",
      "Epoch 142/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1487     \n",
      "Epoch 143/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1484     \n",
      "Epoch 144/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1480     \n",
      "Epoch 145/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1497     \n",
      "Epoch 146/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1493     \n",
      "Epoch 147/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1496     \n",
      "Epoch 148/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1485     \n",
      "Epoch 149/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1406     \n",
      "Epoch 150/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1488     \n",
      "Epoch 151/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1466     \n",
      "Epoch 152/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1485     \n",
      "Epoch 153/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1452     \n",
      "Epoch 154/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1507      \n",
      "Epoch 155/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1490       \n",
      "Epoch 156/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1441     \n",
      "Epoch 157/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1512       \n",
      "Epoch 158/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1494      \n",
      "Epoch 159/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1490     \n",
      "Epoch 160/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1464     \n",
      "Epoch 161/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1475     \n",
      "Epoch 162/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1475      \n",
      "Epoch 163/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1477     \n",
      "Epoch 164/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1478      \n",
      "Epoch 165/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1470      \n",
      "Epoch 166/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1499     \n",
      "Epoch 167/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1473      \n",
      "Epoch 168/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1465     \n",
      "Epoch 169/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1459     \n",
      "Epoch 170/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1460      \n",
      "Epoch 171/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1487      \n",
      "Epoch 172/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1449     \n",
      "Epoch 173/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1501     \n",
      "Epoch 174/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1459     \n",
      "Epoch 175/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1446     \n",
      "Epoch 176/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1473      \n",
      "Epoch 177/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1478     \n",
      "Epoch 178/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1468     \n",
      "Epoch 179/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1462     \n",
      "Epoch 180/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1456      \n",
      "Epoch 181/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1482     \n",
      "Epoch 182/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1442      \n",
      "Epoch 183/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1488     \n",
      "Epoch 184/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1457     \n",
      "Epoch 185/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1466      \n",
      "Epoch 186/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1484      \n",
      "Epoch 187/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1472      \n",
      "Epoch 188/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1447      \n",
      "Epoch 189/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1472     \n",
      "Epoch 190/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1447     \n",
      "Epoch 191/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1438     \n",
      "Epoch 192/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1496     \n",
      "Epoch 193/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1460     \n",
      "Epoch 194/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1450     \n",
      "Epoch 195/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1453      \n",
      "Epoch 196/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1454      \n",
      "Epoch 197/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1463     \n",
      "Epoch 198/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1465     \n",
      "Epoch 199/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1462     \n",
      "Epoch 200/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1454     \n",
      "Epoch 201/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1451     \n",
      "Epoch 202/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1473     \n",
      "Epoch 203/1000\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "232/232 [==============================] - 0s - loss: 0.1446      \n",
      "Epoch 204/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1445      \n",
      "Epoch 205/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1456      \n",
      "Epoch 206/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1460     \n",
      "Epoch 207/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1439     \n",
      "Epoch 208/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1462      \n",
      "Epoch 209/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1434     \n",
      "Epoch 210/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1410      \n",
      "Epoch 211/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1480       \n",
      "Epoch 212/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1438       \n",
      "Epoch 213/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1426     \n",
      "Epoch 214/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1439     \n",
      "Epoch 215/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1433     \n",
      "Epoch 216/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1441     \n",
      "Epoch 217/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1364     \n",
      "Epoch 218/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1471      \n",
      "Epoch 219/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1461     \n",
      "Epoch 220/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1433     \n",
      "Epoch 221/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1434     \n",
      "Epoch 222/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1443     \n",
      "Epoch 223/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1435     \n",
      "Epoch 224/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1442     \n",
      "Epoch 225/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1445     \n",
      "Epoch 226/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1442     \n",
      "Epoch 227/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1445     \n",
      "Epoch 228/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1413     \n",
      "Epoch 229/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1458     \n",
      "Epoch 230/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1442     \n",
      "Epoch 231/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1416      \n",
      "Epoch 232/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1453     \n",
      "Epoch 233/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1417     \n",
      "Epoch 234/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1372      \n",
      "Epoch 235/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1468     \n",
      "Epoch 236/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1420     \n",
      "Epoch 237/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1504     \n",
      "Epoch 238/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1408     \n",
      "Epoch 239/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1467     \n",
      "Epoch 240/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1437     \n",
      "Epoch 241/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1451     \n",
      "Epoch 242/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1439     \n",
      "Epoch 243/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1423     \n",
      "Epoch 244/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1452     \n",
      "Epoch 245/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1443     \n",
      "Epoch 246/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1427     \n",
      "Epoch 247/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1427     \n",
      "Epoch 248/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1439     \n",
      "Epoch 249/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1420     \n",
      "Epoch 250/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1440     \n",
      "Epoch 251/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1422     \n",
      "Epoch 252/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1424       \n",
      "Epoch 253/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1430     \n",
      "Epoch 254/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1471     \n",
      "Epoch 255/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1446     \n",
      "Epoch 256/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1431       \n",
      "Epoch 257/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1419     \n",
      "Epoch 258/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1353     \n",
      "Epoch 259/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1461     \n",
      "Epoch 260/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1413     \n",
      "Epoch 261/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1490       \n",
      "Epoch 262/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1421       \n",
      "Epoch 263/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1446     \n",
      "Epoch 264/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1438     e-0 - ETA: 0s - loss: 0.1110  \n",
      "Epoch 265/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1417     \n",
      "Epoch 266/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1431       \n",
      "Epoch 267/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1439     \n",
      "Epoch 268/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1435     \n",
      "Epoch 269/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1430      \n",
      "Epoch 270/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1435     \n",
      "Epoch 271/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1398     \n",
      "Epoch 272/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1432     \n",
      "Epoch 273/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1447     \n",
      "Epoch 274/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1440     \n",
      "Epoch 275/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1421     \n",
      "Epoch 276/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1410     \n",
      "Epoch 277/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1420     \n",
      "Epoch 278/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1418      \n",
      "Epoch 279/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1408      \n",
      "Epoch 280/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1421     \n",
      "Epoch 281/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1435     \n",
      "Epoch 282/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1456     \n",
      "Epoch 283/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1423     - ETA: 0s - loss: 0.18\n",
      "Epoch 284/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1422     \n",
      "Epoch 285/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1421     \n",
      "Epoch 286/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1424     \n",
      "Epoch 287/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1437     \n",
      "Epoch 288/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1439     \n",
      "Epoch 289/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1416     \n",
      "Epoch 290/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1436     \n",
      "Epoch 291/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1451     \n",
      "Epoch 292/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1407     \n",
      "Epoch 293/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1438       \n",
      "Epoch 294/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1403     \n",
      "Epoch 295/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1423       \n",
      "Epoch 296/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1425       \n",
      "Epoch 297/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1414     \n",
      "Epoch 298/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1400       \n",
      "Epoch 299/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1393       \n",
      "Epoch 300/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1374       \n",
      "Epoch 301/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1468     \n",
      "Epoch 302/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1426       \n",
      "Epoch 303/1000\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "232/232 [==============================] - 0s - loss: 0.1411     \n",
      "Epoch 304/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1405     \n",
      "Epoch 305/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1414     \n",
      "Epoch 306/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1404     \n",
      "Epoch 307/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1425     \n",
      "Epoch 308/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1425     \n",
      "Epoch 309/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1411      \n",
      "Epoch 310/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1436       \n",
      "Epoch 311/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1447     \n",
      "Epoch 312/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1442     \n",
      "Epoch 313/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1434     \n",
      "Epoch 314/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1421     \n",
      "Epoch 315/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1406       \n",
      "Epoch 316/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1344     \n",
      "Epoch 317/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1454       \n",
      "Epoch 318/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1413     \n",
      "Epoch 319/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1438      \n",
      "Epoch 320/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1427     \n",
      "Epoch 321/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1414     \n",
      "Epoch 322/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1471     \n",
      "Epoch 323/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1430       \n",
      "Epoch 324/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1411     \n",
      "Epoch 325/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1405       \n",
      "Epoch 326/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1396     \n",
      "Epoch 327/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1381      \n",
      "Epoch 328/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1399     \n",
      "Epoch 329/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1430     \n",
      "Epoch 330/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1405       \n",
      "Epoch 331/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1378       \n",
      "Epoch 332/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1435     \n",
      "Epoch 333/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1417     \n",
      "Epoch 334/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1423     \n",
      "Epoch 335/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1373     \n",
      "Epoch 336/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1383     \n",
      "Epoch 337/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1432     \n",
      "Epoch 338/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1414       \n",
      "Epoch 339/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1436     \n",
      "Epoch 340/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1400     \n",
      "Epoch 341/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1437       \n",
      "Epoch 342/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1430       \n",
      "Epoch 343/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1433     \n",
      "Epoch 344/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1419     \n",
      "Epoch 345/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1450       \n",
      "Epoch 346/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1410     \n",
      "Epoch 347/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1420     \n",
      "Epoch 348/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1418       \n",
      "Epoch 349/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1446     \n",
      "Epoch 350/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1420     \n",
      "Epoch 351/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1390       \n",
      "Epoch 352/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1426     \n",
      "Epoch 353/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1425     - ETA: 0s - loss: 0.13\n",
      "Epoch 354/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1396       \n",
      "Epoch 355/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1422     \n",
      "Epoch 356/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1448     \n",
      "Epoch 357/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1422       \n",
      "Epoch 358/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1407       \n",
      "Epoch 359/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1418     \n",
      "Epoch 360/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1469     \n",
      "Epoch 361/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1434     \n",
      "Epoch 362/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1430     \n",
      "Epoch 363/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1413     \n",
      "Epoch 364/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1438     \n",
      "Epoch 365/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1409       \n",
      "Epoch 366/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1403      \n",
      "Epoch 367/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1392     \n",
      "Epoch 368/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1421     \n",
      "Epoch 369/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1396     \n",
      "Epoch 370/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1413     \n",
      "Epoch 371/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1410       \n",
      "Epoch 372/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1406     \n",
      "Epoch 373/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1405      \n",
      "Epoch 374/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1406     \n",
      "Epoch 375/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1426     \n",
      "Epoch 376/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1392      \n",
      "Epoch 377/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1409     \n",
      "Epoch 378/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1437      \n",
      "Epoch 379/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1410     \n",
      "Epoch 380/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1410     \n",
      "Epoch 381/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1470     \n",
      "Epoch 382/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1448     \n",
      "Epoch 383/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1399     \n",
      "Epoch 384/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1428     \n",
      "Epoch 385/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1382      \n",
      "Epoch 386/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1401     \n",
      "Epoch 387/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1465     \n",
      "Epoch 388/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1391      \n",
      "Epoch 389/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1433      \n",
      "Epoch 390/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1418     \n",
      "Epoch 391/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1404       \n",
      "Epoch 392/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1389     \n",
      "Epoch 393/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1391     \n",
      "Epoch 394/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1420       \n",
      "Epoch 395/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1392     \n",
      "Epoch 396/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1398     \n",
      "Epoch 397/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1415     \n",
      "Epoch 398/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1402       \n",
      "Epoch 399/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1384     \n",
      "Epoch 400/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1401     \n",
      "Epoch 401/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1395     \n",
      "Epoch 402/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1435     \n",
      "Epoch 403/1000\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "232/232 [==============================] - 0s - loss: 0.1430      \n",
      "Epoch 404/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1423     \n",
      "Epoch 405/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1409       \n",
      "Epoch 406/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1417     \n",
      "Epoch 407/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1410     \n",
      "Epoch 408/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1396     \n",
      "Epoch 409/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1426       \n",
      "Epoch 410/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1398     \n",
      "Epoch 411/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1397       \n",
      "Epoch 412/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1388     \n",
      "Epoch 413/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1485     \n",
      "Epoch 414/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1472     \n",
      "Epoch 415/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1437     \n",
      "Epoch 416/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1398       \n",
      "Epoch 417/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1422     \n",
      "Epoch 418/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1407       \n",
      "Epoch 419/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1365     \n",
      "Epoch 420/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1415     \n",
      "Epoch 421/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1407     \n",
      "Epoch 422/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1394     \n",
      "Epoch 423/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1404     \n",
      "Epoch 424/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1411     \n",
      "Epoch 425/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1412       \n",
      "Epoch 426/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1391     \n",
      "Epoch 427/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1375       \n",
      "Epoch 428/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1417     \n",
      "Epoch 429/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1420       \n",
      "Epoch 430/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1410     \n",
      "Epoch 431/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1419     \n",
      "Epoch 432/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1396       \n",
      "Epoch 433/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1422     \n",
      "Epoch 434/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1425     \n",
      "Epoch 435/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1400     \n",
      "Epoch 436/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1423       \n",
      "Epoch 437/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1403     \n",
      "Epoch 438/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1506     \n",
      "Epoch 439/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1414       \n",
      "Epoch 440/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1434       \n",
      "Epoch 441/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1411     e-0 - ETA: 0s - loss: 0.2104  \n",
      "Epoch 442/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1397     \n",
      "Epoch 443/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1404     \n",
      "Epoch 444/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1421     \n",
      "Epoch 445/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1411     \n",
      "Epoch 446/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1400     \n",
      "Epoch 447/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1408     \n",
      "Epoch 448/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1397     \n",
      "Epoch 449/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1310     \n",
      "Epoch 450/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1446     \n",
      "Epoch 451/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1423     \n",
      "Epoch 452/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1381     \n",
      "Epoch 453/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1395     - ETA: 0s - loss: 0.15\n",
      "Epoch 454/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1390     \n",
      "Epoch 455/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1440       \n",
      "Epoch 456/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1382     \n",
      "Epoch 457/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1417     \n",
      "Epoch 458/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1384     \n",
      "Epoch 459/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1485       \n",
      "Epoch 460/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1396     \n",
      "Epoch 461/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1407      \n",
      "Epoch 462/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1435     \n",
      "Epoch 463/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1403     \n",
      "Epoch 464/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1405     \n",
      "Epoch 465/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1405       \n",
      "Epoch 466/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1436     \n",
      "Epoch 467/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1352     \n",
      "Epoch 468/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1414      \n",
      "Epoch 469/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1357       \n",
      "Epoch 470/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1425     \n",
      "Epoch 471/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1440     \n",
      "Epoch 472/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1414       \n",
      "Epoch 473/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1406     \n",
      "Epoch 474/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1421      \n",
      "Epoch 475/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1406     \n",
      "Epoch 476/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1390     \n",
      "Epoch 477/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1407       \n",
      "Epoch 478/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1418     \n",
      "Epoch 479/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1353     \n",
      "Epoch 480/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1405       \n",
      "Epoch 481/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1402     \n",
      "Epoch 482/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1407     \n",
      "Epoch 483/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1407     \n",
      "Epoch 484/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1389       \n",
      "Epoch 485/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1386       \n",
      "Epoch 486/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1453     \n",
      "Epoch 487/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1413       \n",
      "Epoch 488/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1406     \n",
      "Epoch 489/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1393       \n",
      "Epoch 490/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1389     \n",
      "Epoch 491/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1414       \n",
      "Epoch 492/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1400     \n",
      "Epoch 493/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1423       \n",
      "Epoch 494/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1400     \n",
      "Epoch 495/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1403       \n",
      "Epoch 496/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1412       \n",
      "Epoch 497/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1391     \n",
      "Epoch 498/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1386     \n",
      "Epoch 499/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1385     \n",
      "Epoch 500/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1380     \n",
      "Epoch 501/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1402     \n",
      "Epoch 502/1000\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "232/232 [==============================] - 0s - loss: 0.1402     \n",
      "Epoch 503/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1383       \n",
      "Epoch 504/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1398       \n",
      "Epoch 505/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1422       \n",
      "Epoch 506/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1387     \n",
      "Epoch 507/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1420       \n",
      "Epoch 508/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1426      \n",
      "Epoch 509/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1420     \n",
      "Epoch 510/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1358      \n",
      "Epoch 511/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1415     \n",
      "Epoch 512/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1383       \n",
      "Epoch 513/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1408     e-0 - ETA: 0s - loss: 0.1390  \n",
      "Epoch 514/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1410     \n",
      "Epoch 515/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1412     \n",
      "Epoch 516/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1410      \n",
      "Epoch 517/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1425       \n",
      "Epoch 518/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1402     \n",
      "Epoch 519/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1437       \n",
      "Epoch 520/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1391       \n",
      "Epoch 521/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1407     \n",
      "Epoch 522/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1401       \n",
      "Epoch 523/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1385     \n",
      "Epoch 524/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1385     \n",
      "Epoch 525/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1448       \n",
      "Epoch 526/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1376       \n",
      "Epoch 527/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1403     \n",
      "Epoch 528/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1408       \n",
      "Epoch 529/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1410     \n",
      "Epoch 530/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1390     \n",
      "Epoch 531/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1407       \n",
      "Epoch 532/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1411     \n",
      "Epoch 533/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1409       \n",
      "Epoch 534/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1399      \n",
      "Epoch 535/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1378       \n",
      "Epoch 536/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1392       \n",
      "Epoch 537/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1371     \n",
      "Epoch 538/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1423       \n",
      "Epoch 539/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1361      \n",
      "Epoch 540/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1372     \n",
      "Epoch 541/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1393     \n",
      "Epoch 542/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1423     \n",
      "Epoch 543/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1416     \n",
      "Epoch 544/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1489     \n",
      "Epoch 545/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1409       \n",
      "Epoch 546/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1389     \n",
      "Epoch 547/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1429       \n",
      "Epoch 548/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1431      \n",
      "Epoch 549/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1390      \n",
      "Epoch 550/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1374     \n",
      "Epoch 551/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1415      \n",
      "Epoch 552/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1397      \n",
      "Epoch 553/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1390      \n",
      "Epoch 554/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1414      \n",
      "Epoch 555/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1409      \n",
      "Epoch 556/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1387     \n",
      "Epoch 557/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1377     \n",
      "Epoch 558/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1368     \n",
      "Epoch 559/1000\n",
      "232/232 [==============================] - 0s - loss: 0.1378      \n",
      "Epoch 560/1000\n",
      "130/232 [===============>..............] - ETA: 0s - loss: 0.1197"
     ]
    }
   ],
   "source": [
    "# 2> LM神经网络\n",
    "#构建LM神经网络模型\n",
    "from keras.models import Sequential #导入神经网络初始化函数\n",
    "from keras.layers.core import Dense, Activation #导入神经网络层函数、激活函数\n",
    "\n",
    "netfile = 'net.model' #构建的神经网络模型存储路径\n",
    "net = Sequential() # 建立神经网络\n",
    "net.add(Dense(input_dim = 3, output_dim = 10)) # 添加输入层（3节点）到隐藏层（10节点）的连接\n",
    "net.add(Activation('relu')) # 隐藏层使用relu激活函数（通过实验确定的relu函数）\n",
    "net.add(Dense(input_dim = 10, output_dim = 1)) # 添加隐藏层（10节点）到输出层（1节点）的连接\n",
    "net.add(Activation('sigmoid')) # 输出层使用sigmoid激活函数\n",
    "net.compile(loss = 'binary_crossentropy', optimizer = 'adam',metrics=None)#编译模型，用adam方法求解\n",
    "\n",
    "net.fit(train[:,:3], train[:,3], nb_epoch=1000, batch_size=1)# 训练模型，循环1000次\n",
    "net.save_weights(netfile) #保存模型\n",
    "\n",
    "predict_result = net.predict_classes(train[:,:3]).reshape(len(train)) #预测类别结果变形\n",
    "'''\n",
    "注意：keras使用predict给出预测的概率，使用predict_classes给出预测类别，而且两者预测结果都是nx1维数组\n",
    "'''\n",
    "predict_result1 = net.predict(train[:,:3]).reshape(len(train)) #预测概率结果变形\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 2.1> 画混淆矩阵\n",
    "# 方法1：\n",
    "# from cm_plot import *# 导入自行编写的混淆矩阵可视化函数 等价于下面的语句\n",
    "# cm_plot(train[:,3],predict_result).show()#显示混淆矩阵可视化结果\n",
    "\n",
    "# 方法2：\n",
    "# 导入相关库，生成混淆矩阵\n",
    "from sklearn.metrics import confusion_matrix\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rc('figure',figsize=(5,5))\n",
    "\n",
    "cm = confusion_matrix(train[:,3],predict_result)\n",
    "plt.matshow(cm,cmap = plt.cm.Greens) # 背景颜色\n",
    "plt.colorbar() # 颜色标签\n",
    "\n",
    "# 内部添加图例标签\n",
    "for x in range(len(cm)):\n",
    "    for y in range(len(cm)):\n",
    "        plt.annotate(cm[x,y], xy = (x,y), horizontalalignment = 'center', verticalalignment = 'center')\n",
    "plt.ylabel('True Label')\n",
    "plt.xlabel('Predicted Label')\n",
    "plt.title('LM_train')\n",
    "plt.savefig('confusionMatrix.jpg')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2.2> 计算预测正确率\n",
    "# 方法1 利用混淆矩阵\n",
    "from __future__ import division\n",
    "correctRate = (cm[1,1] + cm[0,0]) / cm.sum()\n",
    "print correctRate\n",
    "\n",
    "# # 方法2 逐一比对\n",
    "# import numpy as np\n",
    "# train_predict_result = np.column_stack((train, predict_result)) # 合并两个矩阵 列合并(***)\n",
    "# num = 0\n",
    "# for i in range(len(train_predict_result)):\n",
    "#     if train_predict_result[i][3] == train_predict_result[i][4]:\n",
    "#         num = num+1\n",
    "# print num/len(train_predict_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 3> 使用CART决策树\n",
    "from sklearn.tree import DecisionTreeClassifier #导入决策树模型\n",
    "\n",
    "treefile = 'tree.pkl' #模型输出名字\n",
    "tree1 = DecisionTreeClassifier() # 建立决策树模型\n",
    "tree1.fit(train[:,:3], train[:,3]) #训练\n",
    "\n",
    "#保存模型, 当数据量比较大时，我们更希望把模型持久化的形式保存在磁盘文件中，而不是以字符串（string）的形式保存在内存中 (***)\n",
    "from sklearn.externals import joblib \n",
    "joblib.dump(tree1, treefile)\n",
    "\n",
    "predict_CartResult = tree1.predict(train[:,:3]) # 使用predict给出预测类别，而且预测结果都是1xN维数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 3.1> 画混淆矩阵\n",
    "# 方法1：\n",
    "# from cm_plot import *# 导入自行编写的混淆矩阵可视化函数 等价于下面的语句\n",
    "# cm_plot(train[:,3],predict_CartResult).show()#显示混淆矩阵可视化结果\n",
    "\n",
    "# 方法2：\n",
    "# 导入相关库，生成混淆矩阵\n",
    "from sklearn.metrics import confusion_matrix\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rc('figure',figsize=(5,5))\n",
    "\n",
    "cm = confusion_matrix(train[:,3], predict_CartResult)\n",
    "plt.matshow(cm,cmap = plt.cm.Blues) # 背景颜色\n",
    "plt.colorbar() # 颜色标签\n",
    "\n",
    "# 内部添加图例标签\n",
    "for x in range(len(cm)):\n",
    "    for y in range(len(cm)):\n",
    "        plt.annotate(cm[x,y], xy = (x,y), horizontalalignment = 'center', verticalalignment = 'center')\n",
    "plt.ylabel('True Label')\n",
    "plt.xlabel('Predicted Label')\n",
    "plt.title('Cart_train')\n",
    "plt.savefig('confusionMatrix1.jpg')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 3.2> 计算预测正确率\n",
    "# 方法1 利用混淆矩阵\n",
    "from __future__ import division\n",
    "correctRate = (cm[1,1] + cm[0,0]) / cm.sum()\n",
    "print correctRate\n",
    "\n",
    "# # 方法2 逐一比对\n",
    "# import numpy as np\n",
    "# train_predict_result = np.column_stack((train, predict_CartResult)) # 合并两个矩阵 列合并(***)\n",
    "# num = 0\n",
    "# for i in range(len(train_predict_result)):\n",
    "#     if train_predict_result[i][3] == train_predict_result[i][4]:\n",
    "#         num = num+1\n",
    "# print num/len(train_predict_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 4> 模型评价\n",
    "# 采用ROC曲线评价方法来测试评估模型分类的性能，一个优秀的分类器应该是尽量靠近左上角的\n",
    "\n",
    "from sklearn.metrics import roc_curve # 导入ROC曲线\n",
    "predict_result = net.predict(test[:,:3]).reshape(len(test)) #预测结果变形\n",
    "fpr, tpr, thresholds = roc_curve(test[:,3], predict_result, pos_label=1)\n",
    "plt.plot(fpr, tpr, linewidth=2, label='ROC of LM') #作出LM的ROC曲线\n",
    "\n",
    "fpr1, tpr1, thresholds1 = roc_curve(test[:,3], tree1.predict_proba(test[:,:3])[:,1], pos_label=1)\n",
    "plt.plot(fpr1, tpr1, linewidth=2, label = 'ROC of CartTree')#做出ROC曲线\n",
    "\n",
    "plt.xlabel('False Positive Rate')\n",
    "plt.ylabel('True Positive Rate')\n",
    "plt.xlim(0,1.05)\n",
    "plt.ylim(0,1.05)\n",
    "plt.legend(loc=4)\n",
    "plt.title('comparation of LM and CartTree')\n",
    "plt.savefig('LOC.jpg')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
